package com.ms;

import com.alibaba.fastjson.JSON;
import com.ms.exmaple.orm.config.ApplicationConfig;
import com.ms.exmaple.orm.entity.User;
import com.ms.exmaple.orm.service.UserService;
import com.ms.orm.conditions.query.LambdaQueryWrapper;
import com.ms.orm.conditions.query.QueryWrapper;
import com.ms.orm.conditions.update.UpdateWrapper;
import com.ms.orm.mapper.GenericMapperFactoryBean;
import com.ms.orm.meta.IPage;
import com.ms.orm.meta.Page;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Hello world!
 */
public class Mapper_App5 {
    public static void main(String[] args) {
        try {
            ApplicationContext app = new AnnotationConfigApplicationContext(ApplicationConfig.class);
            UserService userService = (UserService) app.getBean("userService");


            /////////////  //////////////////////////////////////////////////////////////////
            LambdaQueryWrapper<User> lambdaQueryWrapperSelectPage = new LambdaQueryWrapper<>();
            lambdaQueryWrapperSelectPage.gt(User::getId,"5");
            //lambdaQueryWrapperSelectPage.and(i->i.ne(User::getName,"Userbatch12").like(User::getName,"Userbatch1"));
            //lambdaQueryWrapperSelectPage.or(i->i.eq(User::getName,"Userbatch3").like(User::getName,"事务回滚测试"));
            lambdaQueryWrapperSelectPage.nested(i->i.like(User::getName,"Userbatch1").like(User::getName,"事务回滚测试"));
            lambdaQueryWrapperSelectPage.select(User::getId, User::getName);
            lambdaQueryWrapperSelectPage.orderByDesc(User::getId);
            Object lambdaQueryWrapperSelectPage_res =  userService.selectPage(new Page<>(1,30),lambdaQueryWrapperSelectPage);
            System.err.println("lambdaQueryWrapperSelectPage_res = "+ JSON.toJSONString(lambdaQueryWrapperSelectPage_res));



            List<User> list = userService.selectUsersWithConditions("ww",20);
            System.err.println("selectUsersWithConditions=="+JSON.toJSONString(list));

            IPage<User> page = userService.selectUsersWithConditionPage(new Page<>(3,10),null,20);
            System.err.println("selectUsersWithConditionPage=="+JSON.toJSONString(page));
        }catch (Exception e) {
            e.printStackTrace();
        }
    }


}
